﻿using System.Collections.Generic;
using WindowsForms.AOnline.WindowsForm.BaseUserControls;
using WindowsForms.AOnline.View.Dictionary;
using WindowsForms.AOnline.Presenter.Dictionary.EmployTest;
using WindowsForms.AOnline.WindowsForm.FormBase.PropertyGrid;
using DevExpress.Utils;

namespace WindowsForms.AOnline.WindowsForm.UserControl.Dictionary
{
    public partial class UserControlEmployList : BaseListUserControl, IEmployTestsView  
    {

        private readonly EmployTestsPresenter _employTestsPresenter; 

        public UserControlEmployList()
        {
            InitializeComponent();
            _employTestsPresenter = new EmployTestsPresenter(this);  
        }

        /// <summary>
        /// Deletes the grid.
        /// </summary>
        protected override string DeleteGrid()
        {
           return  new EmployTestPresenter(null).Delete(int.Parse(PrimaryKeyValue));  
        }

        /// <summary>
        /// Loads the data into grid.
        /// </summary>
        protected override void LoadDataIntoGrid(int page)
        {
            TotalPage = _employTestsPresenter.GetPageSize();
            if (page <= TotalPage)
            {
                _employTestsPresenter.Display(page);
            }
        }

        public IList<Model.BusinessObjects.Dictionary.EmployTestModel> EmployTests
        {
            set
            {
                ListBindingSource.DataSource = value;
                gridView.PopulateColumns(value);
                ColumnsCollection.Add(new XtraColumn { ColumnName = "EmployId", ColumnVisible = false, Alignment = HorzAlignment.Center });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "Name", ColumnCaption = "Tên nhân viên", ColumnPosition = 1, ColumnVisible = true, ColumnWith = 150 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "Salary", ColumnCaption = "Lương", ColumnPosition = 2, ColumnVisible = true, ColumnWith = 70 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "DepartmentId", ColumnCaption = "Mã phòng ban", ColumnPosition = 3, ColumnVisible = true, ColumnWith =80 });             
            }
        }
    }
}
